package string.t28;

public class One {
    public int strStr(String haystack, String needle) {
        // 又见双指针
        int i = haystack.length();

        char c = needle.charAt(0);
        int nl = needle.length() - 1;

        for (int j = 0; j < i; j++) {
            if (haystack.charAt(j) == c) {
                int k = j;
                int l = 0;
                while (k < i && k < j + nl && haystack.charAt(k) == needle.charAt(l)) {
                    k++;
                    l++;
                }
                if (l == nl) {
                    return j;
                }
            }
        }
        return -1;
    }
}
